package com.smartboard.network.ui;

import android.app.Activity;
import android.app.Application;
import android.content.Context;
import android.view.View;
import android.view.inputmethod.InputMethodManager;

import com.smartboard.network.client.GameClient;
import com.smartboard.network.game.ChessType;

/**
 * Created by cheas on 2018/8/22.
 */

public class MyApplication extends Application {

    public static int chessType = ChessType.INTER_CHESS;
    public static MyApplication instance;

    @Override
    public void onCreate() {
        super.onCreate();
        new Thread() {
            @Override
            public void run() {
                createGameClient();
            }
        }.start();

        instance = this;
    }

    public static boolean createGameClient() {
        if(GameClient.inst() == null) {
            GameClient.create(chessType);
            return GameClient.inst().connect();
        }
        return true;
    }

    public static void hideKeyboard(Activity activity) {
        View view = activity.getWindow().peekDecorView();
        if (view != null) {
            InputMethodManager inputmanger = (InputMethodManager) activity.getSystemService(Context.INPUT_METHOD_SERVICE);
            inputmanger.hideSoftInputFromWindow(view.getWindowToken(), 0);
        }
    }
}
